var WzQuestionEditDlg = {
    choice: parseInt($("input[name='answer']").last().attr('id')),
    count: parseInt($("div[name='dictItem']").last().attr('id').substring(8)),
    itemTemplate: $("#itemTemplate").html(),//广告问题
    itemTemplate_1: $("#itemTemplate_1").html(),//调查、商家问卷
};
WzQuestionEditDlg.addItem=function () {
    var type = $("#type").val()//问题类型
    var questionType = $("#questionType").val();//问题形式
    if (1== type || 3 == type) {//调查、商家问卷
        if(1==questionType) {
            a = $("div[name='dictItem']").last().attr('id');
            $("#" + a).after(this.itemTemplate_1);
            $("#dictItem_1").attr("id", this.newId());
        }
        if(2==questionType){
            var answerAndPic = "<div class=\"form-group\" name=\"answerAndPic\" style=\"margin-top: 10px\" id=\"answerAndPic\">" +
                "<div>" +
                "        <label class=\"col-sm-2 control-label\">答案</label>\n" +
                "        <div   style='margin-bottom: 1.03%' class=\"col-sm-10\">\n" +
                "            <input type=\"title\" class=\"form-control\" name=\"itemNum\" id=\"text\"\n" +
                "                   style=\"width: 70%;\" >\n" +
                "        </div>\n" +
                " </div>" +
                "<div>" +
                "        <label class=\"col-sm-2 control-label\">图片id</label>\n" +
                "        <div class=\"col-sm-10\" >\n" +
                "            <input type=\"pic\" class=\"form-control\" id=\"fileId\"\n" +
                "                   style=\"width: 20%;\" >\n" +
                "        </div>" +
                " </div>" +
                "<div style='margin-left: 16.7%;margin-top: 10%'><button  style='margin-top: -1.2%' type=\"button\" class=\"btn btn-danger button-margin\"  onclick=\"WzQuestionInfoDlg.deleteItem(event)\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;删除\n" +
                "</button></div>" +
                "</div>";
            a = $("div[name='dictItem']").last().attr('id');
            $("#" + a).after(answerAndPic);
        }
    } else if (2 == type) {//广告问题
        if(1==questionType) {
            a = $("div[name='dictItem']").last().attr('id');
            $("#" + a).after(this.itemTemplate);
            $("#dictItem").attr("id", this.newId());
            $("#choice").attr("id", this.newChoice());
        }
        if(2==questionType){
            var choice=this.newChoice();
            var answerAndPic = "<div class=\"form-group\" name=\"answerAndPic\" style=\"margin-top: 10px\" id=\"answerAndPic\">" +
                "<div>" +
                "        <label class=\"col-sm-2 control-label\">答案</label>\n" +
                "        <div   style='margin-bottom: 1.03%' class=\"col-sm-10\">\n" +
                "            <input type=\"title\" class=\"form-control\" name=\"itemNum\" id=\"text\"\n" +
                "                   style=\"width: 70%;\" >\n" +
                "        </div>\n" +
                " </div>" +
                "<div>" +
                "        <label class=\"col-sm-2 control-label\">图片id</label>\n" +
                "        <div class=\"col-sm-10\" >\n" +
                "            <input type=\"pic\" class=\"form-control\" id=\"fileId\"\n" +
                "                   style=\"width: 20%;\" >\n" +
                "           <div style='margin-top: -3.6%;margin-left: 31.3%'>" +
                "               <label>正确</label>" +
                "               <input  type=\"radio\" name=\"answer\" id=" + choice + "\>" +
                "           </div>" +
                "        </div>" +
                " </div>" +
                "<div style='margin-left: 16.7%;'><button  style='margin-top: -1.2%' type=\"button\" class=\"btn btn-danger button-margin\"  onclick=\"WzQuestionInfoDlg.deleteItem(event)\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;删除\n" +
                "</button></div>" +
                "</div>";
            a = $("div[name='dictItem']").last().attr('id');
            $("#" + a).after(answerAndPic);
        }
    }
}
/**
 * item获取新的id
 */
WzQuestionEditDlg.newId = function () {
    this.count = this.count + 1;
    return "dictItem" + this.count;
};
/**
 * choice获取新的choice
 */

WzQuestionEditDlg.newChoice = function () {
    this.choice = this.choice + 1;
    return this.choice;
};
/**
 * 删除item
 */
WzQuestionEditDlg.deleteItem = function (event) {
    var obj = Feng.eventParseObject(event);
    obj = obj.is('button') ? obj : obj.parent();
    obj.parent().parent().remove();
};

/**
 * 清除为空的item Dom
 */
WzQuestionEditDlg.clearNullDom = function () {
    $("[name='dictItem']").each(function () {
        var num = $(this).find("[name='itemNum']").val();
        var name = $(this).find("[name='itemName']").val();
        if (num == '' || name == '') {
            $(this).remove();
        }
    });
};